package com.example.guideapp.utils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * Created by Administrator on 2017/10/20.
 */

public class MySqliteDatabaseHelper extends SQLiteOpenHelper {

    private Context context;

    public MySqliteDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    public MySqliteDatabaseHelper(Context context){
        super(context,Constant.SQLITEDATABASE_NAME,null,Constant.SQLITEDATABASE_VERSION);
        this.context = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        long i = System.currentTimeMillis();

        db.beginTransaction();

        db.execSQL(Data.FESTIVAL_TABLE);
        db.execSQL(Data.FESTIVALMESSAGE_TABLE);

        db.execSQL(Data.WISHTYPE_TABLE);
        db.execSQL(Data.WISHTYPEMESSAGE_TABLE);
        db.execSQL(Data.MYFESTIVAL_TABLE);

        //Util.insertFestival(db);
        Data.insertFestival(db,context);
        Util.insertFestivalMessage(db);
        //Util.insertWisType(db);
        Data.insertWishType(db,context);
        Util.insertWishTypeMessage(db);

        db.setTransactionSuccessful();
        db.endTransaction();

        Log.e("insert", (System.currentTimeMillis() - i)+"");

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.d("TAG", "onUpgrade: ");
    }
}
